<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<script>
			{
			  // genertaor基本定义
			  let tell=function* (){
			    yield 'a';
			    yield 'b';
			    return 'c'
			  };
			
			  let k=tell();
			
			  console.log(k.next());
			  console.log(k.next());
			  console.log(k.next());
			  console.log(k.next());
			}
			/*{
				let obj = {};
				obj[Symbol.iterator] = function*() {
					yield 1;
					yield 2;
					yield 3;
				}

				for(let value of obj) {
					console.log('value', value);
				}
			}*/
			/*{
			  // 长轮询
			  let ajax=function* (){
			    yield new Promise(function(resolve,reject){
			      setTimeout(function () {
			        resolve({code:0})
			      }, 200);
			    })
			  }
			
			  let pull=function(){
			    let genertaor=ajax();
			    let step=genertaor.next();
			    step.value.then(function(d){
			      if(d.code!=0){
			        setTimeout(function () {
			          console.info('wait');
			          pull()
			        }, 1000);
			      }else{
			        console.info(d);
			      }
			    })
			  }
			
			  pull();
			}*/
		</script>
	</body>

</html>